

function Prompt(elems, context,closecallback) {
  this.context = context ? context : $(document.body);
  this.eles = [];
  this.closecallback=closecallback;
  if (elems) {
    for (var i = 0; i < elems.length; i++) {
      this.eles.push($('<div></div>').attr('id', elems[i].id));
      if (elems[i].html) {
        this.eles[i].html(elems[i].html);
      }
      if (elems[i].style) {
        this.eles[i].css(elems[i].style);
      }
      if (elems[i].handler && typeof elems[i].handler == 'function') {
        elems[i].handler.call(this.eles[i], this);
      }
      this.eles[i].appendTo(this.context);
    }
  }
}

Prompt.prototype.close = function() {
  var elems = this.eles;
  for (var i = elems.length - 1; i >= 0; i--) {
    elems[i].remove();
  }
  if(this.closecallback)
	  this.closecallback();
}

function LoadPrompt(text, context, customHandler) {
  Prompt.call(this, [ {
    id : 'mask',
    handler : customHandler || function() {
      var target = $(window);
      this.height(target.height());
      this.width(target.width());
    }
  }, {
    id : 'login'
  }, {
    id : 'info_text',
    html : text
  } ], context);
}

function NavigationPrompt(html) {
  Prompt.call(this, [ {
    id : 'mask_more',
    handler : function(prompt) {
      var target = $(window);
      this.height(target.height());
      this.width(target.width());
      this.on('click', function() {
        prompt.close.call(prompt);
      });
    }
  }, {
    id : 'more_alert',
    html : html,
    handler : function(prompt) {
      this.find('#account').on('click', function() {
        var isAdmin = localCache.getSessionItem('isAdmin');
        if (isAdmin) {// 管理员
          location.assign('account_recharge.html');
        } else
          location.assign('account.html');
      });
      this.find('#help').on('click', function() {
         location.assign('help.html');
      });
    },
    style : {
      top : '43px'
    }
  } ]);
}

function UserPrompt(html,func) {
  Prompt.call(this, [{
    id : 'mask_more',
    handler : function(prompt) {
      var target = $(window);
      this.height(target.height());
      this.width(target.width());
    }
  }, {
    id : 'make_sure',
    html : '<p>' + html + '</p><div class="input_ok" id="confirm">确定</div>',
    handler : function(prompt) {
      $(document).on('click', '#confirm', function() {
        prompt.close.call(prompt);
      });
    }
  }],null,func);
}

function ConfirmPrompt(text,func) {
	var $this=this;
    Prompt.call(this, [{
    	handler:function() {
    	      var target = $(window);
    	      this.height(target.height());
    	      this.width(target.width());
    	 },
    	 id:'mask'
        },{
    	id:'alert_tip',
		html:'<p>'+text+'</p><div class="btn" ><span class="bordeR" id="save">确定</span><span id="cancel">取消</span></div>',
	    handler : function(prompt) {
	        $(document).on('click', '#cancel', function() {
	            prompt.close();
	        });
	        $(document).on('click', '#save', function() {
	        	func.save(prompt);
		    });
	      }
    }]);
}


$(function() {
  UserPrompt.prototype = NavigationPrompt.prototype = LoadPrompt.prototype =ConfirmPrompt.prototype=new Prompt();
  

});
